

set(LibPath "${CMAKE_CURRENT_LIST_DIR}/../install/libShared")

find_path(
        SHARED_INCLUDE_DIR
        NAMES LibShared.hpp
        PATHS ${LibPath}
        NO_DEFAULT_PATH
)

find_library(
        SHARED_LIB_DEBUG
        NAMES "libSharedd.lib"
        PATHS "${LibPath}"
        NO_DEFAULT_PATH
)

find_library(
        SHARED_LIB_RELEASE
        NAMES "libShared.lib"
        PATHS "${LibPath}"
        NO_DEFAULT_PATH
)

message(STATUS "LibPath:${LibPath}")
message(STATUS "SHARED_INCLUDE_DIR:${SHARED_INCLUDE_DIR}")
message(STATUS "SHARED_LIB_DEBUG:${SHARED_LIB_DEBUG}")
message(STATUS "SHARED_LIB_RELEASE:${SHARED_LIB_RELEASE}")

if(NOT TARGET MyLibShared)
    # 将目标设置为在项目中全局可见 GLOBAL
    add_library(MyLibShared SHARED IMPORTED GLOBAL)
    # 为导入目标添加相关属性
    set_target_properties(MyLibShared PROPERTIES
            INTERFACE_INCLUDE_DIRECTORIES "${SHARED_INCLUDE_DIR}"
#            IMPORTED_LOCATION "libShared.so" #linux 需要使用IMPORTED_LOCATION属性
            IMPORTED_IMPLIB "${SHARED_LIB_RELEASE}"
            IMPORTED_IMPLIB_DEBUG "${SHARED_LIB_DEBUG}"
            IMPORTED_IMPLIB_RELEASE "${SHARED_LIB_RELEASE}"
            MAP_IMPORTED_CONFIG_MINSIZEREL Release
            MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
    )
endif()

#set(SHARED_LIBS ${SHARED_LIB_DEBUG} ${SHARED_LIB_RELEASE})
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(SHARED_LIBS ${SHARED_LIB_DEBUG})
else ()
    set(SHARED_LIBS ${SHARED_LIB_RELEASE})
endif ()

# 这里用到了一个 CMake 自带的函数，会根据指定内容设置 MyLibShared_FOUND 变量
include(FindPackageHandleStandardArgs)

# 如果 SHARED_LIBS或SHARED_INCLUDE_DIR 为空，则 MyLibShared_FOUND 将被设置为 FALSE，并在使用 find_package(LibShared REQUIRED) 时也会报错
# 否则MyLibShared_FOUND设置为 TRUE
find_package_handle_standard_args(
        MyLibShared
        REQUIRED_VARS SHARED_LIBS SHARED_INCLUDE_DIR
)
